package com.qf.token.controller;

import com.qf.common.vo.ResultVo;
import com.qf.token.utils.TokenUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TokenController {

    @GetMapping("/validate")
    public ResultVo validate(String token){
        boolean b = TokenUtils.checkToken(token);
        if (b){
            return new ResultVo(1,"ok",null);
        }else {
            return new ResultVo(-1,"token error",null);
        }
    }

    @GetMapping("/create")
    public ResultVo createToken(String username,Integer userid,Integer time){

        System.out.println(username);
        System.out.println(userid);
        System.out.println(time);

        String token = TokenUtils.createToken(username, userid, time);

        return new ResultVo(1, "ok", token);

    }

}
